# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/5/29 22:32
from PyQt5.Qt import *


class Window(QWidget):
	def __init__(self):
		super().__init__()
		self.setWindowTitle('QTabWidget学习')
		self.resize(500, 500)
		self.setup_ui()

	def setup_ui(self):
		page_1 = QWidget()
		tw = QTabWidget(self)

		btn = QPushButton("测试按钮", self)
		btn.move(350, 20)
		lb_1 = QLabel("这是第一个标签页", page_1)
		lb_1.move(100, 100)

		tw.move(50, 50)
		tw.resize(400, 400)

		tw.addTab(page_1, "Tab1")
		tw.addTab(QWidget(), 'Tab2')
		tw.addTab(QWidget(), 'Tab3')
		tw.addTab(QWidget(), 'Tab4')

		# 移除页
		# btn.clicked.connect(lambda: tw.removeTab(2))

		# 页不可用
		# QTabWidget
		# btn.clicked.connect(lambda :tw.setTabEnabled(0,False))

		# 清空页
		def test_slot():
			print("page_1:",page_1)
			print('page_1.parentWidget:',page_1.parentWidget())
			tw.clear()
			print("page_1:", page_1)
			print('page_1.parentWidget:', page_1.parentWidget())

		btn.clicked.connect(test_slot)


if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	window = Window()
	window.show()
	sys.exit(app.exec_())
